﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using proRFID_DiemDanh.Chung;

namespace proRFID_DiemDanh.Lop
{
    public partial class SuaLop : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                khoacbo(0);
                ddl_khoa.SelectedValue=Request["makhoa"];
                txt_tenlop.Text = Request["tenlop"];
                if (string.IsNullOrEmpty( Request["IDLop"]))
                    Response.Redirect("../Lop/Lop.aspx");
                txt_tenlop.Focus();
            }
        }
        void khoacbo(int makhoa)
        {
            ddl_khoa.DataSource = mdLop.Khoa_DDL();
            ddl_khoa.DataValueField = "MAKHOA";
            ddl_khoa.DataTextField = "TENKHOA";
            ddl_khoa.DataBind();
        }

        protected void cmd_sua_Click(object sender, ImageClickEventArgs e)
        {
            DataTable dt = mdLop.lop_update(Convert.ToInt32(Request["IDLop"]), Convert.ToInt32(ddl_khoa.SelectedValue), txt_tenlop.Text);
            if (dt.Rows[0]["ErrCode"].ToString() == "0")
            {
                mdMain.OKBox(this, dt.Rows[0]["ErrMsg"].ToString(), "/Lop/Lop.aspx");
            }
            else 
            {
                mdMain.OKCancelBox(this, dt.Rows[0]["ErrMsg"].ToString() , "/Lop/Lop.aspx");
                txt_tenlop.Focus();
            }
        }
    }
}